const express = require("express");
const webpack = require("webpack");
const webpackDevMiddleWare = require("webpack-dev-middleware");

const app = express();
const config = require("./webpack.config.js");
const compiler = webpack(config);
// console.log("compiler ======> ", compiler);
// 告知 express 使用 webpack-dev-middleware，
// 以及将 webpack.config.js 配置文件作为基础配置。
const serverDev = webpackDevMiddleWare(compiler, {
  publicPath: config.output.publicPath,
});
app.use(serverDev);

// 将文件 serve 到 port 3000。
app.listen(3000, function () {
  console.log("Example app listening on port 3000!\n");
  // console.log('serverDev ==> ', serverDev)
});
